package me.zhengjie.modules.weixin.message;

import com.alibaba.fastjson.JSON;
import me.zhengjie.modules.weixin.message.reply.AbstractReplyMessage;

import java.util.Map;

/**
 * 命中的回复规则
 */
public class AnalyzerReplyMessage {

    private String module;

    private String rule;

    private Integer priority;

    private boolean inContext;

    private String replyType;

    private ReplyMessage<? super AbstractReplyMessage> replyMsg;

    private Map<String, Object> receiveMsg;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public ReplyMessage<? super AbstractReplyMessage> getReplyMsg() {
        return replyMsg;
    }

    public void setReplyMsg(ReplyMessage<? super AbstractReplyMessage> replyMsg) {
        this.replyMsg = replyMsg;
    }

    public Map<String, Object> getReceiveMsg() {
        return receiveMsg;
    }

    public void setReceiveMsg(Map<String, Object> receiveMsg) {
        this.receiveMsg = receiveMsg;
    }

    public String getModule() {
        return module;
    }

    public void setModule(String module) {
        this.module = module;
    }

    public String getRule() {
        return rule;
    }

    public void setRule(String rule) {
        this.rule = rule;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public void setInContext(boolean inContext) {
        this.inContext = inContext;
    }

    public boolean isInContext() {
        return inContext;
    }

    public String getReplyType() {
        return replyType;
    }

    public void setReplyType(String replyType) {
        this.replyType = replyType;
    }

    public static class ReplyMessage<T> {
        private T msgBody;

        public ReplyMessage() {

        }

        public ReplyMessage(T msgBody) {
            this.msgBody = msgBody;
        }

        public T getMsgBody() {
            return msgBody;
        }

        public void setMsgBody(T msgBody) {
            this.msgBody = msgBody;
        }

        public T convertReplyMessage(Class<T> clazz) {
            return JSON.parseObject(JSON.toJSONString(msgBody), clazz);
        }
    }
}
